home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 9 / PC World Interactive 9 - Temmuz 1998.iso / muzik / FMSYNTH.EXE / STMB.PAS < prev    next >
Pascal/Delphi Source File  |  1994-01-30  |  8KB  |  202 lines

  1. (* STMB.PAS -- Pascal Programming interface for FMSYNTH.DRV
  2.  *             Copyright (c) 1993 by Jamie O'Connell
  3.  *
  4.  * Currently six functions are defined: GetTimbre, SetTimbre, GetParm, 
  5.  * SetParm, GetPercMap, and SetPercMap.  With Version 2.0 of the driver
  6.  * GetPercMap and SetPercMap are somewhat obsolete, but will still be
  7.  * supported.  In addition, GetParm and SetParm operate on the Driver
  8.  * System Parameters.     
  9.  * 
  10.  * Get Timbre retrieves the Timbre parameters from the specified location.
  11.  *
  12.  * SetTimbre will change the sound of an instrument in either working 
  13.  * storage or the sound of an instrument stored within a RAM Timbre Bank.
  14.  * 
  15.  * GetParm retrieves the FM Synth system parameters
  16.  * SetParm sets the System Parameters
  17.  *     
  18.  * *** OBSOLETE ***
  19.  * GetPercMap and SetPercMap perform equivalent functions on the internal
  20.  * percussion map: which note plays which percussion timbre at what pitch.
  21.  *
  22.  *
  23.  * NOTE - In version 1.x of the driver, only 47 percussion timbres were
  24.  *        stored -- implementing the General MIDI percussion map.  For
  25.  *        version 2.0, we store an entire 128 timbre bank for percussion.
  26.  *        In addition, the Pitch parameter which used to be in the Percussion
  27.  *        map is now stored directly in the Timbre, and the position within
  28.  *        the bank defines the MIDI Key mapping. For instance, the Timbre
  29.  *        stored in slot 35 of the percussion bank is the first GM Bass Drum.
  30.  *
  31.  *        Passing the obsolete TMB_BANK_PERCUSSION to GetTimbre will continue 
  32.  *        to retrieve one of the 47 GM percussion timbres.  For example,
  33.  *        requesting Timbre 0 will retrieve percussion Timbre 35.  To access
  34.  *        the entire Percussion bank use the new TMB_PERCUSSION constant.     
  35.  *     
  36.  * **************************************************************************
  37.  *
  38.  * Working storage is the current version of a Timbre stored on a 
  39.  * per-channel basis.  It is the version of the timbre which is used to
  40.  * sound a voice for the channel when a note is to be played. The working 
  41.  * storage is overwritten by Bank storage whenever a program change is 
  42.  * received for the channel.
  43.  *
  44.  * The RAM Timbre bank is either the internal Timbre Bank, or one which 
  45.  * has been loaded from a file.  In either case it is volatile storage
  46.  * which is overwritten when the bank is reloaded.
  47.  *)
  48.  
  49. unit STmb;
  50.  
  51. interface
  52.  
  53. uses WinTypes, WinProcs;
  54.  
  55. const
  56.   TMB_WORKING_STORAGE  =  0;
  57.   TMB_BANK_STORAGE     =  1;
  58.   TMB_BANK_PERCUSSION  =  2;
  59.   TMB_PERCUSSION       =  3; (* Use this to retrieve percussion now *)
  60.  
  61.   FIRSTDRUMNOTE = 35;
  62.   LASTDRUMNOTE  = 81;
  63.   NUMDRUMNOTES  = (LASTDRUMNOTE - FIRSTDRUMNOTE + 1);
  64.  
  65. Type
  66.  
  67. (* The timbre definition (IBK - SBI Format) *)
  68.  
  69.   PTmbRec = ^TmbRec;
  70.   TmbRec  = Record
  71.     MSndChr : Byte;
  72.     CSndChr : Byte;
  73.     MKSLOut : Byte;
  74.     CKSLOut : Byte;
  75.     MAtkDcy : Byte;
  76.     CAtkDcy : Byte;
  77.     MSusRel : Byte;
  78.     CSusRel : Byte;
  79.     MWavSel : Byte;
  80.     CWavSel : Byte;
  81.     FDBkCon : Byte;
  82.     PercVoc : Byte;     (* New for version 1.x -- Bass Drum=6, Snare=7 *)
  83.                         (* Tom-Tom=8,  Cymbal=9, HiHat=10 *)
  84.     Transps : ShortInt; (* New for version 1.x -- # of semitones offset *)
  85.     PrcPitch: BYTE;     (* New for version 2.0 - the MIDI Pitch *)
  86.     Future2 : Word;
  87.   end;
  88.  
  89.   PSysParm = ^SysParm;
  90.   SysParm  = Record
  91.     Stereo     : Byte;     (* 1 = on, 0 = off *)
  92.     Percussion : Byte;     (* 1 = on, 0 = off *)
  93.     PerChannel : Byte;     (* if Percussion mode = 1: channel = 0-15 *)
  94.                            (* (i.e. MIDI channel 10 is value 9)      *)
  95.     DftBank    : Byte;     (* 0-4 (Bank1 - Bank5) *)
  96.     VibDepth   : Byte;     (* 0 = light, 1 = deep *)
  97.     TremDepth  : Byte;     (* 0 = light, 1 = deep *)
  98.     BendRange  : Byte;     (* 0-12 semitones (1 octave) *)
  99.     SvSettings : Byte;     (* 1 = Save the settings in the INI file *)
  100.     ChanMap    : Array[1..16] of Byte; 
  101.                            (* 1 = on, 0 = off -- one byte per channel *)
  102.     PercBoost  : ShortInt; (* signed: -64 to +63 -- 0 is no boost *)
  103.   end;
  104.  
  105. (* *** OBSOLETE ******************************************************* *)
  106. PercElem = Record
  107.     patch : Byte;
  108.     note  : Byte;
  109.   end;
  110.  
  111.  
  112. PPercMap = ^PercMap;
  113. PercMap  = Array [1..NUMDRUMNOTES] of PercElem;
  114.  
  115.  
  116. (* The percussion map provides info for each pecussion MIDI key
  117.  * To access (retrieve or send) the Percussion map you create an
  118.  * array of these things: PERCMAP percMap[NUMDRUMNOTES];
  119.  * and pass it to GetPercMap or SetPercMap.  The buffer must be at least
  120.  * sizeof(PERCMAP) * NUMDRUMNOTES = 94 bytes large.
  121.  *)
  122.  
  123. Procedure GetPercMap(lpPM: PPercMap); Far;
  124. Procedure SetPercMap(lpPM: PPercMap); Far;
  125.  
  126. (* ********************************************************************* *)
  127.  
  128. Function GetTimbre(wLoc: Word; lpTmb: PTmbRec; wSrc: Word): Word;  Far;
  129. Function SetTimbre(wLoc: Word; lpTmb: PTmbRec; wDest: Word): Word; Far;
  130.  
  131. (*
  132.  *  DESCRIPTION
  133.  *
  134.  *  wLoc - If the Destination (wDest) or Source (wSrc) is TMB_WORKING_STORAGE,
  135.  *         then wLoc is the channel number (0 based) for storing the Timbre.
  136.  *         If the Destination is TMB_BANK_STORAGE, then the most
  137.  *         significant byte of wLoc (HIBYTE(wLoc)) is the Bank number
  138.  *         (valid values: 0 - 4), and the least significant byte is the
  139.  *         timbre number (0-127).
  140.  *         If the destination is TMB_PERC_BANK, the Bank number is ignored
  141.  *         (there is only one percussion bank), and the LSB is the timbre
  142.  *         number (0-46).
  143.  *
  144.  *  lpTmb  A far pointer to a TIMBRE structure, defining the new timbre to
  145.  *         store.  The structure should be the full 16 bytes in length.
  146.  *
  147.  *  wSrc   This value determines how wLoc is interpreted when retrieving
  148.  *         the timbre.  If wSrc is TMB_WORKING_STORAGE the timbre is retrieved
  149.  *         from working storage (wLoc is a channel number). If wSrc is
  150.  *         TMB_BANK_STORAGE, the timbre is retrieved from the specified
  151.  *         bank and timbre slot (wLoc is the combination of Bank & Timbre#).
  152.  *
  153.  *  wDest  This value determines how wLoc is interpreted and the final
  154.  *         destination for the timbre.  If wDest is ST_WORKING_STORAGE the
  155.  *         channel timbre info is updated, and future voices on channel will
  156.  *         sound this timbre. If wDest is ST_BANK_STORAGE, both the Bank
  157.  *         Timbre, and any channels set to this Bank and Timbre are updated.
  158.  *         Any future notes playing this bank and timbre will sound the
  159.  *         timbre.
  160.  *
  161.  *  Return Value
  162.  *         If all goes well, 0 is returned, otherwise a non-zero value is
  163.  *         returned indicating, an incorrect or out-of-range parameter.
  164.  *         The values within the TIMBRE structure itself are not checked
  165.  *         for validity, but stored as supplied.
  166.  *)
  167.  
  168.  
  169. Function GetParm(lpSysParm: PSysParm; StructLen: Word): Word; Far;
  170. Function SetParm(lpSysParm: PSysParm; StructLen: Word): Word; Far;
  171.  
  172.  
  173. (*   
  174.  *  DESCRIPTION
  175.  *
  176.  *  lpSysParm   - a FAR pointer to a SYSPARM struct as shown above.  All
  177.  *                parameters are retrieved and set at once.  When setting
  178.  *                parameters the driver is reinitialized so the driver
  179.  *                is reset when the function returns.
  180.  *
  181.  *  StructLen     Is the size of SYSPARM.  Passing this value allows future
  182.  *                additions and modifications to the structure.
  183.  *
  184.  *  Return Value
  185.  *         If all goes well, 0 is returned, otherwise a non-zero value is
  186.  *         returned indicating, an incorrect or out-of-range parameter.  
  187.  *     
  188.  *)
  189.  
  190. implementation
  191.  
  192. Procedure GetPercMap;  external 'FMSYNTH' index  9;
  193. Procedure SetPercMap;  external 'FMSYNTH' index 10;
  194.  
  195. Function GetTimbre;    external 'FMSYNTH' index  7;
  196. Function SetTimbre;    external 'FMSYNTH' index  8;
  197.  
  198. Function GetParm;      external 'FMSYNTH' index 11;
  199. Function SetParm;      external 'FMSYNTH' index 12;
  200.  
  201. end.
  202.